package com.platform.base.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Log {
    // 定义一个全局的记录器，通过LoggerFactory获取
    private final static Logger mLogger = LoggerFactory.getLogger("FILE");

    public static void d(String msg) {
        mLogger.debug(msg);
    }
    public static void d(String format, Object... arguments) {
        mLogger.debug(format, arguments);
    }
    public static void d(String msg, Exception e) {
        mLogger.debug(getExceptionInfo(msg, e), e);
    }
    public static void d(Exception e) {
        mLogger.debug(getExceptionInfo("", e), e);
    }

    public static void i(String msg) {
        mLogger.info(msg);
    }
    public static void i(String format, Object... arguments) {
        mLogger.info(format, arguments);
    }
    public static void i(String msg, Exception e) {
        mLogger.info(getExceptionInfo(msg, e), e);
    }
    public static void i(Exception e) {
        mLogger.info(getExceptionInfo("", e), e);
    }

    public static void w(String msg) {
        mLogger.warn(msg);
    }
    public static void w(String format, Object... arguments) {
        mLogger.warn(format, arguments);
    }
    public static void w(String msg, Exception e) {
        mLogger.warn(getExceptionInfo(msg, e), e);
    }
    public static void w(Exception e) {
        mLogger.warn(getExceptionInfo("", e), e);
    }

    public static void e(String msg) {
        mLogger.error(msg);
    }
    public static void e(String format, Object... arguments) {
        mLogger.error(format, arguments);
    }
    public static void e(String msg, Exception e) {
        mLogger.error(getExceptionInfo(msg, e), e);
    }
    public static void e(Exception e) {
        mLogger.error(getExceptionInfo("", e), e);
    }

    protected static String getExceptionInfo(String msg, Exception e) {
        if (e instanceof RuntimeException) {
            RuntimeException bre = (RuntimeException) e;
            return String.format("msg: %s, success : %s, userTips : %s", msg, false, bre.getMessage());
        } else
            return msg;
    }
}
